<template>
  <div class="search_container">
    <el-form ref="form" inline :model="form">
      <el-form-item label="名称">
        <el-input v-model="form.name" clearable></el-input>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="form.idCard" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="serchForm">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button @click="add">加一{{ count }}</el-button>
      </el-form-item> -->
    </el-form>
    <div class="btn">
      <el-button :icon="Plus">新增用户</el-button>
    </div>
  </div>
</template>

<script setup lang="ts" name="searchCom">
import { userSearch } from '@/type/role'
import { reactive, inject } from "vue"
import { Plus } from '@element-plus/icons-vue'
// 接收父组件
// interface Props {
//   form?: userSearch,
// }
// defineProps<Props>()
const props = defineProps({
  form: {
    default: {
      name: '',
      idCard: ''
    },
    require: true
  }
})
const count = inject('count')
const changeCount: any = inject('changeCount')
const add = () => {
  changeCount(1)
}

// 重置
const reset = reactive<userSearch>({
  name: '',
  idCard: ''
})

// 向父组件传值
// 注册emit自定义事件
const emit = defineEmits(["changeFormValue", "searchForm"])
const resetForm = () => {
  emit("changeFormValue", reset)
}

// 搜索
const serchForm = () => {
  emit("searchForm", props.form)
}
</script>

<style scoped lang="less">
.search_container {
  .btn {
    margin: 15px 0px;
  }
}
</style>